import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton } from '../Common/options'
import { MaterialFactory, Material } from '../Common/Conversion'

export const MaterialBatch = async ({ url, OptionsEvent, ClientData, Permission }) => {
    const materialFactoryUuid = await MaterialFactory()
    const materialUuid = await Material()

    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            Permission?.findIndex(v => v.uuid === '78d26228-8cf3-49cd-8bcf-31e1bedb1011') !== -1 && (
                <AddDataButton OptionsEvent={OptionsEvent} url={url} type="primary" icon="add" title="新增材料追溯" />
            ),
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'MaterialBatch' },
            {
                dataIndex: 'entryTime',
                title: '进场时间',
                valueType: 'Date',
                showTime: true,
                width: 200,
                hideInSearch: true,
            },
            { ...commonTableList.tableName, title: '材料批次名称' },
            {
                dataIndex: 'materialFactoryUuid',
                title: '供应商',
                valueType: 'select',
                valueEnum: materialFactoryUuid,
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'materialUuid',
                title: '材料名称',
                valueType: 'select',
                valueEnum: materialUuid,
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'materialName',
                title: '材料名称',
                valueType: 'input',
                rules: true,
                width: 200,
                hideInModify: true,
                hideInAdded: true,
                hideInTable: true,
            },

            {
                dataIndex: 'spec',
                title: '型号',
                valueType: 'hidden',
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'num',
                title: '收货数量',
                valueType: 'inputNumber',
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'supplyNum',
                title: '发货数量',
                valueType: 'inputNumber',
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'unit',
                title: '单位',
                valueType: 'hidden',
                width: 100,
                hideInSearch: true,
            },

            {
                dataIndex: 'carNumber',
                title: '车牌号',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            commonTableList.BeginEntryTime,
            commonTableList.EndEntryTime,
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        Permission.findIndex(v => v.uuid === '1593a1da-1a66-4c1e-af3c-a1ac31bd8aca') !== -1 && (
                            <ModDataButton
                                OptionsEvent={OptionsEvent}
                                key="modify"
                                title="修改"
                                url={url}
                                data={record}
                            />
                        ),
                        Permission.findIndex(v => v.uuid === '452c663a-1d40-45a9-adaf-49133a6f6acb') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
